package test;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.List;

//import nicg.st.Communicate;
import nicg.st.controller.XmlController;
import nicg.st.entity.IPParseBean;
import nicg.st.entity.SingleUnit;
import nicg.st.util.XmlParseIp;

import com.alibaba.fastjson.JSON;
import com.bingqi.MsgTrans1;
import com.bingqi.RecvFileCallback;
import com.bingqi.SendFileCallback1;
import com.bingqi2.Dtml;
import com.bingqi2.Dtml.getSingleUnitJsonResult;

public class dtmlClass {
	static final RecvFileCallback recvfilecallback = new RecvFileCallback() {	
		@Override
		public void RecvFileonData(byte[] filename, byte[] source ,long filelength, long currentlong) {
			String fileString = null;
			try {
				fileString = new String(filename,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("收到文件");
			System.out.println("filename = " + fileString);
			System.out.println("filelength = " + filelength);
			System.out.println("currentlong = " + currentlong);
			if(currentlong == filelength){
				System.out.println("收到文件完成，文件名为："+ fileString);
			}
		}
		
	};
	
static final SendFileCallback1 sendCallBack = new SendFileCallback1() {
		
		@Override
		public void SendFileonData(byte[] fileName, byte[] fromIp, byte[] toIp,
				long total, long current) {
						
		}
	};
	public static void main(String[] args){
		
//		Communicate.startService();
		
		List<IPParseBean> ips = XmlParseIp.getIPParseBeans(new File("./config/ip.xml"));
		
		
		String filename = "./send.xml";//文件路径名称
    	String targetIp = "bitcsXml" + "10.10.1.9"; //ips.get(0).getIP()
    	System.out.println(targetIp);
    	String sourceIp = "xxzt";//源ip地址
    	char type = 0x01; //传输类型
    	MsgTrans1.sendFile_(filename.getBytes(), targetIp.getBytes(), sendCallBack, sourceIp.getBytes(), type, 0, 0, 0);
//		Dtml dtml = new Dtml();	
//		if(dtml.init()){
//			String currentId = dtml.getUnitId();
//			getSingleUnitJsonResult res = dtml.getSingleUnitJson(currentId);
//			System.out.println(currentId);
//			System.out.println(res.json);
//			System.out.println("==========");
//			getUnitAttrResult value = dtml.getUnitAttr(currentId, "JDLX");
//			System.out.println(value.attrValue);
//			value = dtml.getUnitAttr(currentId, "RYLX");
//			System.out.println(value.attrValue);
			
//			MsgTrans1.init_();
//			String myIp = "";
//			try {
//				myIp = InetAddress.getLocalHost();
//			} catch (UnknownHostException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			System.out.println("222" + dtmlClass.getFinalIp());
//			String currentId = dtml.getUnitId();
//			getSingleUnitJsonResult res = dtml.getSingleUnitJson(currentId);
//			String json = res.json;
//			SingleUnit singleUnit = JSON.parseObject(json,SingleUnit.class);
//			String myIp = "123bit"; //singleUnit.getUnit().getCommElement().getIP();
//			String typeString = "bitcsXml" + myIp; // "bitcsXml";
//			String filepath = "receive";
//			//MsgTrans1.registeFileApp_(typeString.getBytes(), recvfilecallback, filepath.getBytes());
//			System.out.println("DTML服务开启成功");
		
			
//			MsgTrans1.init_();
//			
//			String currentId = dtml.getUnitId();
//			getSingleUnitJsonResult res = dtml.getSingleUnitJson(currentId);
//			String json = res.json;
//			SingleUnit singleUnit = JSON.parseObject(json,SingleUnit.class);
//			String myIp = "123bit"; //singleUnit.getUnit().getCommElement().getIP();
//			String typeString = "bitcsXml" + myIp; // "bitcsXml";
//			String filepath = "receive";
//			int ret = MsgTrans1.registeFileApp_(typeString.getBytes(), recvfilecallback, filepath.getBytes());
//			System.out.println("3333333333333333333333333" + ret);
//			System.out.println("DTML服务开启成功");
//		}
//		System.out.println("==========");
//		System.out.println(DTMLHelper.getLocalIp());
//		File f = new File("./config/ip.xml");
//		List<IPParseBean> ips = XmlParseIp.getIPParseBeans(f);
//		for(int i = 0;i< ips.size();i++){
//			System.out.println(ips.get(i).toString());
//		}
		
		
		
//		Dtml dtml = new Dtml();
//		dtml.init();
		
		
		
	}
}
